package chenjiuxu.seniorui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Shader;
import android.text.TextPaint;
import android.util.AttributeSet;

/**
 * Created by 15705 on 2017/12/28.
 */

public class TheNeonLightsTextView extends android.support.v7.widget.AppCompatTextView {
    private LinearGradient linearGradient;
    private TextPaint paint;
    private Matrix matrix;
    public TheNeonLightsTextView(Context context) {
        super(context);
    }
    public TheNeonLightsTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public TheNeonLightsTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        paint = getPaint();
        String s = getText().toString();
        int lengthText = (int) paint.measureText(s) / s.length() * 3;
        int[] colors = new int[]{0x22000000, Color.RED, 0x22000000};
        linearGradient = new LinearGradient(0, 0, lengthText, 0, colors, null, Shader.TileMode.CLAMP);
        paint.setShader(linearGradient);
        matrix = new Matrix();


    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }
}
